<?php
App::uses('AppModel', 'Model');
/**
 * Variant Model
 *
 * @property Product $Product
 */
class Variant extends AppModel {

	public $name = "Variant";
	#Variant status
	const typeStatus = 0;
	const active = 1; #Save as hide
	const disactive = 0; #Save as show

	#Variant Image 
	const typeImage = 1;
	const smallCode = 'small';
	const mediumCode = 'medium';
	const bigCode = 'big';
	const zoomCode = 'zoom';

/**
 * Validation rules
 *
 * @var array
 */
	public $validate = array(
		'price' => array(
			'decimal' => array(
				'rule' => array('decimal'),
				'message' => 'Decimal',
				'allowEmpty' => true,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'raw_price' => array(
			'decimal' => array(
				'rule' => array('decimal'),
				'message' => 'Decimal',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'status' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'is_master' => array(
			'boolean' => array(
				'rule' => array('boolean'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'hand_on' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'product_id' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
	);

	//The Associations below have been created with all possible keys, those that are not needed can be removed

/**
 * belongsTo associations
 *
 * @var array
 */
	public $belongsTo = array(
		'Product' => array(
			'className' => 'Product',
			'foreignKey' => 'product_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);

	var $hasMany = array(
      'Image' => array(
          'foreignKey' => 'owner_id',
          'conditions' => array('Image.owner_model' => 'Variant')
      )
  );

	public $hasAndBelongsToMany = array(
      'OptionValue' =>
          array(
              'className'              => 'OptionValue',
              'joinTable'              => 'option_values_variants',
              'foreignKey'             => 'variant_id',
              'associationForeignKey'  => 'option_value_id',
              'unique'                 => true,
              'conditions'             => '',
              'fields'                 => '',
              'order'                  => '',
              'limit'                  => '',
              'offset'                 => '',
              'finderQuery'            => '',
              'deleteQuery'            => '',
              'insertQuery'            => ''
          )
  );

}
